package com.woniuxy.personal.core.controller;


import com.woniuxy.common.CommonResult;
import com.woniuxy.personal.core.model.PlCart;
import com.woniuxy.personal.core.service.PlCartService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author gmx
 * @since 2021-06-29
 */
@Api(tags = "购物车相关接口")
@RestController
@RequestMapping("/cart")
public class PlCartController {

    @Autowired
    PlCartService plCartService;

    /**
     * Description : 购物车  <br/>
     * ChangeLog : 1. 创建 (2021/6/30 19:41 [binhu]);
     *
     * @param userId
     * @return com.woniuxy.common.CommonResult<java.util.List < com.woniuxy.personal.core.model.PlCart>>
     */
    @ApiOperation(value = "购物车")
    @GetMapping("/selectAll")
    public CommonResult<List<PlCart>> selectAll(Integer userId) {
        List<PlCart> carts = plCartService.selectAll(userId);
        return CommonResult.success(carts);
    }

    /**
     * Description : 删除购物车
     * ChangeLog : 1. 创建 (2021/7/2 16:01 [fulang]);
     *
     * @param ids
     * @return com.woniuxy.common.CommonResult
     */
    @ApiOperation(value = "删除购物车")
    @GetMapping("/deleteCart")
    public CommonResult deleteCart(@RequestBody List<Integer> ids) {
        System.out.println(ids);

        int i = plCartService.deleteCart(ids);
        if (i > 0) {
            return CommonResult.success();
        }
        return CommonResult.fail("删除商品失败");
    }
}

